package cn.lsc.system.controller;

import cn.lsc.basic.controller.util.JsonResult;
import cn.lsc.basic.controller.util.PageList;

import cn.lsc.system.domain.Systemdictionarydetail;
import cn.lsc.system.query.SystemdictionarydetailQuery;
import cn.lsc.system.service.ISystemdictionarydetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;


@RestController
@RequestMapping("/systemdictionarydetail")
@Api(value = "部门的API",description="部门相关的CRUD功能")
public class SystemdictionarydetailController {
    @Autowired
    private ISystemdictionarydetailService ISystemdictionarydetailService;

   /* @GetMapping("/detailTree")
    public List<Systemdictionarydetail> deptTree(){
        return ISystemdictionarydetailService.deptTree();
    }*/

    /*
    * 查询所有
    * */
    @GetMapping
    public List<Systemdictionarydetail> findAll(){
       return ISystemdictionarydetailService.findAll();
    }


    /*
    * 查询一个
    * */
    @GetMapping("/{id}")
    public Systemdictionarydetail findById(@PathVariable("id") Long id){
        return ISystemdictionarydetailService.findById(id);
    }

    /*
    * 修改和添加操作
    * */

    @PutMapping
    public JsonResult UpdateOrAdd(@RequestBody Systemdictionarydetail Systemdictionarydetail){
        try {
            if(Systemdictionarydetail.getId()==null){
                ISystemdictionarydetailService.add(Systemdictionarydetail);
            }else {
                ISystemdictionarydetailService.update(Systemdictionarydetail);
            }
            return JsonResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me().setMsg("操作失败");
        }
    }
    /*
    * 删除操作
    * */

    @DeleteMapping("/{id}")
    public JsonResult delete(@PathVariable("id") Long id){
        try {




            ISystemdictionarydetailService.del(id);
            return JsonResult.me();
        }
        catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me().setMsg("操作失败");
        }
    }
    /*
    * 分页查询
    * */

    @PostMapping
    public PageList<Systemdictionarydetail> pageList(@RequestBody SystemdictionarydetailQuery query){
        try {
           return ISystemdictionarydetailService.queryPage(query);
        } catch (Exception e) {
            e.printStackTrace();
            return new PageList();
        }
    }
    /**
     * 批量删除
     * @param ids
     * @return
     */
    @PatchMapping
    @ApiOperation(value = "批量删除接口")
    public JsonResult patchDelete(@RequestBody List<Long> ids){
        try {
            ISystemdictionarydetailService.patchDelete(ids);
            return JsonResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me().setMsg("操作失败");
        }
    }
    /**
     *  根据typesID查询数据数据字典明细
     */
    @GetMapping("/loadByTypeId/{type_id}")
    public List<Systemdictionarydetail> loadByTypeId(@PathVariable("type_id") Long typesId) {
        return ISystemdictionarydetailService.loadByTypeId(typesId);
    }


}
